#include "friendinfopage.h"
#include <QPainter>
#include <QStyleOption>
#include "global.h"
#include "ui_friendinfopage.h"
FriendInfoPage::FriendInfoPage(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::FriendInfoPage)
    , _friendInfo(nullptr)
{
    ui->setupUi(this);
    setObjectName("FriendInfoPage");
    // 文字消息按钮
    connect(ui->message_btn, &QPushButton::clicked, this, &FriendInfoPage::slot_messageBtnClicked);
    // 视频通话按钮
    connect(ui->video_btn, &QPushButton::clicked, this, &FriendInfoPage::slot_videoBtnClicked);
    // 语音通话按钮
    connect(ui->telephone_btn, &QPushButton::clicked, this, &FriendInfoPage::slot_speechBtnClicked);
}

FriendInfoPage::~FriendInfoPage()
{
    delete ui;
}

void FriendInfoPage::setFriendInfo(std::shared_ptr<FriendInfo> friendInfo)
{
    _friendInfo = friendInfo;
    QPixmap p(friendInfo->icon);
    p = p.scaled(ui->friend_icon->size());
    ui->friend_icon->setPixmap(p);
    ui->friend_name_lb->setText(friendInfo->name);
    ui->friend_remark_lb->setText(friendInfo->remark);
}

void FriendInfoPage::slot_messageBtnClicked()
{
    emit sig_messageBtnClicked(_friendInfo);
}

void FriendInfoPage::slot_videoBtnClicked()
{
    emit sig_videoBtnClicked(_friendInfo);
}

void FriendInfoPage::slot_speechBtnClicked()
{
    emit sig_speechBtnClicked(_friendInfo);
}

void FriendInfoPage::paintEvent(QPaintEvent *event)
{
    // 创建一个QStyleOption对象
    QStyleOption opt;
    opt.initFrom(this);
    // 创建一个QPainter对象，用于绘制
    QPainter p(this);
    // 使用样式表绘制控件
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
    // 调用父类的paintEvent方法，处理其他绘制事件
    QWidget::paintEvent(event);
}
